mc.game.menu = function(){};
mc.game.menu.draw = function(data){
	mc.cmd.draw_left("game/main-menu",data);
	this.title = $("#menu_title");
	this.panel = $("#menu_panel");
	this.title.click(this.click).mouseenter(this.show);
	this.panel.hover(this.show,this.hide);
	this.select(data.start);
};
mc.game.menu.show = function(){
	var panel = mc.game.menu.panel;
	if(panel.data("showed")){
		if(panel.data("hid")){
			window.clearTimeout(panel.data("hid"));
			panel.data("hid",false);
		}
	}else{
		panel.data("showed",true);
		panel.show();
	}
}
mc.game.menu.hide_real = function(){
	var panel = mc.game.menu.panel;
	if(panel.data("hid")){
		window.clearTimeout(panel.data("hid"));
		panel.data("hid",false);
	}
	panel.data("showed",false);
	panel.hide();
}
mc.game.menu.hide = function(){
	var panel = mc.game.menu.panel;
	if(panel.data("showed")){
		if(panel.data("hid")){
			window.clearTimeout(panel.data("hid"));
		}
		panel.data("hid",window.setTimeout(mc.game.menu.hide_real,300));
	}
}
mc.game.menu.click = function(){
	var panel = mc.game.menu.panel;
	if(panel.data("showed")){
		mc.game.menu.hide_real();
	}else{
		mc.game.menu.show();
	}
}
mc.game.menu.select = function(index){
	var panel = this.panel;
	var current = panel.find("> div.menu-item:eq("+index+")");
	var item = current.find(">a.mc");
	var cmd = item.attr("command");
	if(item.attr("selectable")){
		if(this.menu_curent != undefined){
			panel.find("> div.menu-item:eq("+this.menu_curent+")").removeClass("selected");
		}
		this.menu_curent = index;
		current.addClass("selected");
		this.title.html(item.html());
	}
	this.hide_real();
	mc.cmd.get_left_inner(2).empty();
	mc.cmd.run(cmd);
}
